export const useImageUpload = () => {
  const isLoading = ref(false);
  const error = ref<string | null>(null);

  const uploadImage = async (file: File) => {
    isLoading.value = true;
    error.value = null;

    try {
      const formData = new FormData();
      formData.append("image", file);

      const response = await $fetch("/api/upload/image", {
        method: "POST",
        body: formData,
        headers: {
          Accept: "application/json",
        },
      });

      return response;
    } catch (err: any) {
      error.value = err.message || "上传失败，请重试";
      throw err;
    } finally {
      isLoading.value = false;
    }
  };

  return {
    uploadImage,
    isLoading,
    error,
  };
};
